package sbj.wizcore;

import com.alibaba.fastjson.JSON;
import sbj.wizcore.common.FmHelper;
import sbj.wizcore.dao.WizDocumentDao;
import sbj.wizcore.domain.WizDocument;
import sbj.wizcore.domain.WizTag;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class GenHtml {


    public static void main(String args[]) {

//        List<WizDocument> docs =  wizDocumentDao.getAllDocuments();
//        System.out.println(JSON.toJSONString(docs));

        //==标签树
        WizDocumentDao wizDocumentDao = new WizDocumentDao();
        List<WizTag> trees = wizDocumentDao.getAllTagTrees();

        System.out.println(JSON.toJSONString(trees));

        trees.forEach(tag -> {
            genTagFile(tag);
        });


        System.out.println("生成成功!");


    }


    //生成标签树
    public static void genTagFile(WizTag root) {

        Map<String, Object> datas = new HashMap<String, Object>();
        datas.put("tag", root);

        FmHelper.geneFile(
                "template.flt", datas,
                GenHtml.class.getResource("../../").getPath() + "html/" + root.getTagName() + ".html"
        );

    }

}
